package com.aim.common.handler;

import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

import java.util.Properties;

/**
 * @AUTO 读取YML文件工具类
 * @Author AIM
 * @DATE 2019/4/19
 */
public class FitPropertiesYml {

    private static String PROPERTY_NAME = "application-dev.yml";

    public static Object getConfigByKey(String key) {
        Resource resource = new ClassPathResource(PROPERTY_NAME);
        Properties properties = null;
        try {
            YamlPropertiesFactoryBean yamlFactory = new YamlPropertiesFactoryBean();
            yamlFactory.setResources(resource);
            properties = yamlFactory.getObject();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }

        return properties.get(key);
    }
}
